package cn.dhnep.demo.service.impl;

import cn.dhnep.demo.mapper.UserMapper;
import cn.dhnep.demo.pojo.User;
import cn.dhnep.demo.pojo.frontvo.UserAddCount;
import cn.dhnep.demo.pojo.vo.RespPageBean;
import cn.dhnep.demo.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author dhn
 * @since 2021-08-26
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public RespPageBean pageQueryAllUser(Integer current, Integer size, Integer gender, String userName, String nickName) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(gender)) wrapper.eq("gender", gender); //性别
        if (!StringUtils.isEmpty(userName)) wrapper.like("user_name", userName); //姓名
        if (!StringUtils.isEmpty(nickName)) wrapper.like("nick_name", nickName); //微信名

        Page<User> page = new Page<>(current, size); //分页数据
        baseMapper.selectPage(page, wrapper);
        return new RespPageBean(0, page.getTotal(), page.getRecords());
    }

    @Override
    public List<UserAddCount> getYesterdayAddUser() {
        return baseMapper.getYesterdayAddUser();
    }


    @Override
    public Integer userCount(String userPhone) {
        return baseMapper.userCount(userPhone);
    }

    @Override
    public List<UserAddCount> getYesterdayAddByHorseman() {
        return baseMapper.getYesterdayAddByHorseman();
    }
}
